home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows4 / pcproj.zip / RESOURCE.CLS < prev    next >
Text File  |  1988-11-30  |  5KB  |  199 lines

  1. /* Resources are used to complete Tasks.  Resources have
  2.    associated costs.  Examples of Resources would be a 
  3.    person or a machine.  Resources are kept in a collection.
  4.  
  5.    When assigning resources their availability and usage
  6.    should be tracked.  This is not yet implemented.
  7. */!!
  8.  
  9. inherit(Object, #Resource, #(
  10. name          /* description   */
  11. fixedCost     /* per usage     */
  12. variableCost  /* per time used */
  13. references    /* set of Tasks  */
  14. maximum       /* Not yet used  */
  15. usage         /* Not yet used  */), 2, nil)!!
  16.  
  17. now(ResourceClass)!!
  18.  
  19. /* Create a new Resource. */
  20. Def  new(self)
  21.   ^init(new(self:Behavior));
  22. }!!
  23.  
  24. now(Resource)!!
  25.  
  26. /* Delete a resource.  First check to see if it is
  27.    used anywhere and check with the user. */
  28. Def  delete(self, project)
  29.   if size(references) = 0
  30.     cor yesNoBox(loadString(PW_WARNING),
  31.                  loadString(PW_RESOURCE) + " " + name +
  32.                  loadString(PW_RESUSE) + CR_LF +
  33.                  loadString(PW_DELETE)) == IDYES
  34.      do(references,
  35.        {using(aTask) 
  36.         removeResource(aTask, self);
  37.      });
  38.     remove(project.resources, self.name);    
  39.   endif;      
  40. }!!
  41.  
  42. /* Return a string of all activities that reference a resource. */
  43. Def  getRefsString(self | str)
  44.   str := "";
  45.   do(references,
  46.     {using(ref) 
  47.      str := str + getName(ref) + " ";
  48.   });
  49.  
  50.   if size(str) > 20 then
  51.     str := subString(str, 0, 18) + "..";
  52.   endif;
  53.   ^str;
  54. }!!
  55.  
  56. /* Return a string to be used as a caption in a window. */
  57. Def  makeCaption(self)
  58. {
  59.   ^loadString(PW_RESOURCE) + ": "+getName(self);
  60. }!!
  61.  
  62. /* Get the amount used of a resource. */
  63. Def  getUsed(self | used)
  64.   used := 0;
  65.   do(references,
  66.     {using(aTask)
  67.      used := used + getTime(aTask);
  68.    });
  69.   ^used;
  70. }!!
  71.  
  72. /* Summarize useful information on a single line. */
  73. Def  getInfoLine(self | used, str)
  74. {
  75.   used := getUsed(self);
  76.   if maximum cand used > maximum
  77.      str := "*";
  78.   else
  79.      str := " ";
  80.   endif;
  81.   ^str 
  82.    + field(name, 6) 
  83.    + field(asString(getMaximum(self)), 3) + " " 
  84.    + field(asString(used), 3) + " "
  85.    + field(asString(getFixedCost(self)), 3) + " " 
  86.    + field(asString(getVariableCost(self)), 3) + " "
  87.    + field(getRefsString(self),20);
  88. }!!
  89.  
  90. /* Set the values of a resource. 
  91.    Values is an array of name, maximum,
  92.    fixedCost, variableCost. */
  93. Def  setValues(self, values)
  94. {
  95.   name := values[0];
  96.   maximum := values[1];
  97.   setFixedCost(self, values[2]);
  98.   setVariableCost(self, values[3]);
  99. }!!
  100.  
  101. /* Display and edit the resource information. 
  102.    The dialog should define methods run() and setEditItem().
  103. */
  104. Def  editInfo(self | dlg, retValue)
  105. {
  106.   showWaitCurs();
  107.   dlg := new(ResDialog); 
  108.   setEditItem(dlg, self);
  109.   retValue := run(dlg, ThePort);
  110.   showOldCurs();
  111.   ^retValue;
  112. }!!
  113.  
  114. /* Print a resource. */
  115. Def  printOn(self, aStream)
  116.   printOn(name, aStream);
  117. }!!
  118.  
  119. /* Set the name of a resource. */
  120. Def  setName(self, aName)
  121. { name := aName;
  122. }!!
  123.  
  124. /* Set the variableCost of a resource.  If necessary,
  125.    update the cost of any Tasks that reference it. */
  126. Def  setVariableCost(self, aCost | oldCost)
  127.   if (aCost <> variableCost)
  128.     oldCost := variableCost;
  129.     variableCost := aCost;
  130.     do(references,
  131.       {using(aTask) updateCost(aTask, variableCost - oldCost);
  132.     });
  133.   endif;
  134. }!!
  135.  
  136. /* Get the variableCost of a resource. */
  137. Def  getVariableCost(self)
  138. { ^variableCost;
  139. }!!
  140.  
  141. /* Set the fixedCost of a resource.  If necessary,
  142.    update the cost of any Tasks that reference it. */
  143. Def  setFixedCost(self, aCost | oldCost)
  144.   if (aCost <> fixedCost)
  145.     oldCost := fixedCost;
  146.     fixedCost := aCost;
  147.     do(references,
  148.       {using(aTask) updateCost(aTask, fixedCost - oldCost);
  149.     });
  150.   endif;
  151. }!!
  152.  
  153. /* Get the fixedCost of a resource. */
  154. Def  getFixedCost(self)
  155. { ^fixedCost;
  156. }!!
  157.  
  158. /* Remove a reference to a resource. */
  159. Def  removeReference(self, aTask)
  160. { remove(references, aTask);
  161. }!!
  162.  
  163. /* Add a reference to a resource. */
  164. Def  addReference(self, aTask)
  165. { add(references, aTask);
  166. }!!
  167.  
  168. /* Get the maximum available of a resource. */
  169. Def  getMaximum(self)
  170. { if maximum
  171.     ^maximum;
  172.   else
  173.     ^"";
  174.   endif;
  175. }!!
  176.  
  177. /* Get the name of a resource. */
  178. Def  getName(self)
  179. { ^name;
  180. }!!
  181.  
  182. /* Initialize a new resource. */
  183. Def  init(self)
  184. {
  185.   name := "";
  186.   maximum := nil;              /* unlimited */
  187.   variableCost := 0;
  188.   fixedCost := 0;
  189.   references := new(Set, 10);  /* where used */
  190. }!!
  191.  
  192.